﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Database;
using CE.AreaCountry;
using CE.Global;
using CE.PersonalAccident;
using CE.PostCode;
using CE.TravelInsurance;
using CE.User;
using CE.Security;
using CE.StreetDirectory;
using CE.Payment;

public partial class travel_insurance_proposalforms_etiqa_proposal_form : System.Web.UI.Page
{
    //string _PlanName = "";
    //string _TripType = "";
    //Int64 _AreaID = 0;
    //Int64 _CountryID = 0;
    string _InsuredType = "";

    public static Int64 _TAId, _TAMoreId, _UserId, _CXCTypeId, _ProviderId, _AgentId;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["mtaid"] != null && Request.QueryString["mpid"] != null
           && Request.QueryString["muid"] != null && Request.QueryString["mtarid"] != null && Request.QueryString["mplan"] != null)
        {
            if (Session["PlanType"] == null)
                Session["PlanType"] = Request.QueryString["mplan"].ToString();

            Session[CE.Global.General.TAId] = Request.QueryString["mtaid"].ToString();
            Session[General.ProviderCompanyId] = Request.QueryString["mpid"].ToString();
            Session[CE.Global.General.TAResultId] = Request.QueryString["mtarid"].ToString();

            if (Request.QueryString["muid"].ToString() != "0")
                Session[General.UserId] = Request.QueryString["muid"].ToString();
        }

        if (Session[CE.Global.General.TAId] == null)
        {
            //Response.Redirect("~/travel-insurance/travel-quote.aspx");
            Response.Redirect("~/travel-insurance/");

        }

        if (Session[CE.Global.General.TAId] != null)
        {
            if (Session[General.ProviderCompanyId] == null)
            {
                BackToResults();
            }
            if (Session[General.ProviderCompanyId].ToString() != "30")
            {
                BackToResults();
            }
        }
        else
        {
            Response.Redirect("~/user/viewresulthistory.aspx");
        }

        if (!Page.IsPostBack)
        {
            lblProvider.Text = "Etiqa Insurance";
            //ClearSession();
            ChangeDateSettings();
            LoadSummary();

            #region Validation Effect
            txtFirstname.Attributes.Add("onblur", "ShowValidationEffect('" + txtFirstname.ClientID + "','" + rfvFirstname.ClientID + "')");
            txtSurname.Attributes.Add("onblur", "ShowValidationEffect('" + txtSurname.ClientID + "','" + rfvSurname.ClientID + "')");
            txtEmailAddress.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmailAddress.ClientID + "','" + rfvEmailAddress.ClientID + "','" + revEmailAddress.ClientID + "')");

            txtNameOfInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameOfInsured.ClientID + "','" + rfvNameOfInsured.ClientID + "')");
            txtInsured.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsured.ClientID + "','" + rfvInsured.ClientID + "')");
            txtSpouse.Attributes.Add("onblur", "ShowValidationEffect('" + txtSpouse.ClientID + "','" + rfvSpouse.ClientID + "')");

            txtNameOfInsuredGiven.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameOfInsuredGiven.ClientID + "','" + rfvNameOfInsuredGiven.ClientID + "')");
            txtInsuredGiven.Attributes.Add("onblur", "ShowValidationEffect('" + txtInsuredGiven.ClientID + "','" + rfvInsuredGiven.ClientID + "')");
            txtSpouseGiven.Attributes.Add("onblur", "ShowValidationEffect('" + txtSpouseGiven.ClientID + "','" + rfvSpouseGiven.ClientID + "')");

            txtNoOfChild.Attributes.Add("onblur", "ShowValidationEffect('" + txtNoOfChild.ClientID + "','" + rfvNoOfChild.ClientID + "')");
            txtChildName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1.ClientID + "','" + rfvChildName1.ClientID + "','" + revChildName1.ClientID + "')");
            txtChildName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2.ClientID + "','" + rfvChildName2.ClientID + "','" + revChildName2.ClientID + "')");
            txtChildName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3.ClientID + "','" + rfvChildName3.ClientID + "','" + revChildName3.ClientID + "')");
            txtChildName4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4.ClientID + "','" + rfvChildName4.ClientID + "','" + revChildName4.ClientID + "')");
            txtChildName5.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5.ClientID + "','" + rfvChildName5.ClientID + "','" + revChildName5.ClientID + "')");

            txtChildName1Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1Given.ClientID + "','" + rfvChildName1Given.ClientID + "','" + revChildName1Given.ClientID + "')");
            txtChildName2Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2Given.ClientID + "','" + rfvChildName2Given.ClientID + "','" + revChildName2Given.ClientID + "')");
            txtChildName3Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3Given.ClientID + "','" + rfvChildName3Given.ClientID + "','" + revChildName3Given.ClientID + "')");
            txtChildName4Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4Given.ClientID + "','" + rfvChildName4Given.ClientID + "','" + revChildName4Given.ClientID + "')");
            txtChildName5Given.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5Given.ClientID + "','" + rfvChildName5Given.ClientID + "','" + revChildName5Given.ClientID + "')");

            #endregion

            txtUnit2.Attributes.Add("onkeyup", "ShowHideDiv('divInsured',true);");

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();


            if (Session[General.UserId] != null)
            {
                ShowUserDetails();
            }
            else if (Session[General.TAPersonnelId] != null
                && Session[General.TAUserName] != null
                && Session[General.TAPhoneNo] != null
                && Session[General.TAEmail] != null)
            {
                txtFirstname.Text = Session[General.TAUserName].ToString();
                txtMobileNo.PhoneNo = Session[General.TAPhoneNo].ToString();
                txtEmailAddress.Text = Session[General.TAEmail].ToString();

                txtInsuredGiven.Text = Session[General.TAUserName].ToString();
                txtNameOfInsuredGiven.Text = Session[General.TAUserName].ToString();
            }
        }


    }

    protected void LoadSummary()
    {
        Int64 TAId = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {

            txtNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            txtNoOfChild.Text = _taapplicantsearch.NoofChilds.ToString();
            txtNoOfAdult.Text = _taapplicantsearch.NoofAdults.ToString();

            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
            lblQref.Text = "TIE" + convertno;
            lblPolicyType.Text = GetPolicy(_taapplicantsearch.PlanType.ToString());
            lblTrip.Text = _taapplicantsearch.TripType.ToString();
            lblCover.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblCoverageType.Text = GetCoverage(_taapplicantsearch.TripType.ToString());
            lblCoverage.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblTotalPremium.Text = String.Format("{0:0,0.00}", Convert.ToDouble(_taapplicantsearch.TotalPremium.ToString())); ;
            lblNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            inNoOfTravellers.Value = _taapplicantsearch.NoOfTravellers.ToString();
            //lblInsCoverage.Text = GetPlanName(_taapplicantsearch.PlanType.ToString(), _taapplicantsearch.CoverageLevel.ToString());
            lblDuration.Text = _taapplicantsearch.Duration.ToString();
            lblAdultAge.Text = _taapplicantsearch.AdultAge.ToString();
            lblChildAge.Text = _taapplicantsearch.ChildAge.ToString();

            inPlanName.Value = _taapplicantsearch.Info2.Trim();
            inTripType.Value = _taapplicantsearch.TripType.Trim();
            inCountryId.Value = _taapplicantsearch.CountryID.ToString();
            inInsuredType.Value = _taapplicantsearch.PlanType.Trim();

            usrDOBPolicyHolder.Year = _taapplicantsearch.DOBAdult1.Year;
            usrDOBPolicyHolder.Month = _taapplicantsearch.DOBAdult1.Month;
            usrDOBPolicyHolder.Day = _taapplicantsearch.DOBAdult1.Day;

            if (txtNoOfAdult.Text.Trim() == "1")
            {
                usrDOB.Year = _taapplicantsearch.DOBAdult1.Year;
                usrDOB.Month = _taapplicantsearch.DOBAdult1.Month;
                usrDOB.Day = _taapplicantsearch.DOBAdult1.Day;
                usrDOB.IsEnabled = false;
            }
            else
            {
                usrDOBinsured.Year = _taapplicantsearch.DOBAdult1.Year;
                usrDOBinsured.Month = _taapplicantsearch.DOBAdult1.Month;
                usrDOBinsured.Day = _taapplicantsearch.DOBAdult1.Day;
                usrDOBinsured.IsEnabled = false;

                usrDOBSpouse.Year = _taapplicantsearch.DOBAdult2.Year;
                usrDOBSpouse.Month = _taapplicantsearch.DOBAdult2.Month;
                usrDOBSpouse.Day = _taapplicantsearch.DOBAdult2.Day;
                usrDOBSpouse.IsEnabled = false;

            }


            lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
            lblStart.Text = _taapplicantsearch.StartDate.ToString();
            lblEnd.Text = _taapplicantsearch.EndDate.ToString();

            if (_taapplicantsearch.TripType == "A")
            {
                //lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy}", _taapplicantsearch.StartDate);            
                inAreaId.Value = _taapplicantsearch.AreaID.ToString();
            }
            else
            {
                //lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
                //lblStart.Text = _taapplicantsearch.StartDate.ToString();
                //lblEnd.Text = _taapplicantsearch.EndDate.ToString();

                inAreaId.Value = (GetAreaIdByCountryID(_taapplicantsearch.CountryID)).ToString();

            }

            if (_taapplicantsearch.AreaID != 0)
                lblDestination.Text = GetAreaName(_taapplicantsearch.AreaID);
            else
                lblDestination.Text = GetCountryName(_taapplicantsearch.CountryID);


            Int32 _AdultCount = Convert.ToInt32(txtNoOfAdult.Text.Trim());

            Int32 _ChildCount = Convert.ToInt32(txtNoOfChild.Text.Trim());
            if (_ChildCount > 0)
            {
                ddlChildDOB1.Day = _taapplicantsearch.DOBChild1.Day;
                ddlChildDOB1.Month = _taapplicantsearch.DOBChild1.Month;
                ddlChildDOB1.Year = _taapplicantsearch.DOBChild1.Year;

                ddlChildDOB2.Day = _taapplicantsearch.DOBChild2.Day;
                ddlChildDOB2.Month = _taapplicantsearch.DOBChild2.Month;
                ddlChildDOB2.Year = _taapplicantsearch.DOBChild2.Year;

                ddlChildDOB3.Day = _taapplicantsearch.DOBChild3.Day;
                ddlChildDOB3.Month = _taapplicantsearch.DOBChild3.Month;
                ddlChildDOB3.Year = _taapplicantsearch.DOBChild3.Year;

                ddlChildDOB4.Day = _taapplicantsearch.DOBChild4.Day;
                ddlChildDOB4.Month = _taapplicantsearch.DOBChild4.Month;
                ddlChildDOB4.Year = _taapplicantsearch.DOBChild4.Year;

                ddlChildDOB5.Day = _taapplicantsearch.DOBChild5.Day;
                ddlChildDOB5.Month = _taapplicantsearch.DOBChild5.Month;
                ddlChildDOB5.Year = _taapplicantsearch.DOBChild5.Year;

                ddlChildDOB6.Day = _taapplicantsearch.DOBChild6.Day;
                ddlChildDOB6.Month = _taapplicantsearch.DOBChild6.Month;
                ddlChildDOB6.Year = _taapplicantsearch.DOBChild6.Year;


                pnlChildsParticulars.Visible = true;
                if (_ChildCount == 1)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = false;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(false);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 2)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 3)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 4)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 5)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 6)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = true;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(true);
                }
            }
            else
            {
                pnlChildsParticulars.Visible = false;
                ValidateChild1(false);
                ValidateChild2(false);
                ValidateChild3(false);
                ValidateChild4(false);
                ValidateChild5(false);
                ValidateChild6(false);
            }

        }
    }

    protected string GetPlanName(string plantype, string coveragelevel)
    {
        string planname = "";
        TAQuoteResult _taresult = new TAQuoteResult();
        TAQuoteResultDB _tadb = new TAQuoteResultDB();

        _taresult = _tadb.GetTASelectSingleItemSelected(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), GetPolicy(plantype), coveragelevel);

        if (_taresult != null)
        {
            planname = _taresult.PlanName;
        }

        return planname;
    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";
        divIndividual.Visible = false;
        divWithspouse.Visible = false;

        if (covertype == "IND")
        {
            policy = "Individual";
            divIndividual.Visible = true;
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
            divWithspouse.Visible = true;
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
            divIndividual.Visible = true;
        }
        else if (covertype == "FML")
        {
            policy = "Family";

            if (txtNoOfAdult.Text != "1")
            {
                divWithspouse.Visible = true;
            }
            else
            {
                divIndividual.Visible = true;

            }
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }

    protected string GetCoverageLevel(string coverage)
    {
        string coveragelevel = "Standard";

        if (coverage == "STD")
            coveragelevel = "Standard";
        else if (coverage == "MED")
            coveragelevel = "Medium";
        else if (coverage == "HGH")
            coveragelevel = "High";

        return coveragelevel;
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected Int64 GetAreaIdByCountryID(Int64 countryid)
    {
        Int64 AreaID = 0;

        AreaCountryInfoDB _areacountryinfodb = new AreaCountryInfoDB();
        AreaID = _areacountryinfodb.GetAreaIDByCountryID(countryid);

        return AreaID;
    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        if (Session[CE.Global.General.TAId] != null)
        {
            if (Session[General.ProviderCompanyId].ToString() != "30")
            {
                BackToResults();
            }
        }
        else
        {
            BackToResults();
        }

        lblMessage.Text = "";
        CheckValidation();
        ChangeValidationEffectServerSide("travel_insurance");

        if (IsValid)
        {
            Int64 _tamoreresult = 0;
            TAMoreDetailEtiqa _TAMoreDetailEtiqa = new TAMoreDetailEtiqa();
            TAMoreDetailEtiqaDB _TAMoreDetailEtiqadb = new TAMoreDetailEtiqaDB();

            _TAMoreDetailEtiqa.cetaMoreDetailId = 0;
            _TAMoreDetailEtiqa.cetaInsId = Convert.ToInt64(Session[General.TAResultId].ToString());
            _TAMoreDetailEtiqa.cetaId = Convert.ToInt64(Session[General.TAId].ToString()); //TAAppSeaID 
            _TAMoreDetailEtiqa.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
            _TAMoreDetailEtiqa.Name = txtSurname.Text.ToUpper() + " " + txtFirstname.Text.ToUpper();
            _TAMoreDetailEtiqa.PostalCode = txtPostCode.Text;
            _TAMoreDetailEtiqa.UnitNo = txtUnit1.Text.Trim();
            _TAMoreDetailEtiqa.HomeNo = txtUnit2.Text.Trim();
            _TAMoreDetailEtiqa.Address = txtAddress.Text.Trim();
            _TAMoreDetailEtiqa.Gender = usrGenderPolicyHolder.GetGender();
            _TAMoreDetailEtiqa.DOB = usrDOBPolicyHolder.GetDate();
            _TAMoreDetailEtiqa.NRICNo = ddlNRICPolicyHolder.GetIdNumber();
            _TAMoreDetailEtiqa.Nationality = ddlNationality.GetNationality();
            _TAMoreDetailEtiqa.MobileNo = txtMobileNo.GetPhoneNo();
            _TAMoreDetailEtiqa.HomePhoneNo = txtResidentialPhoneNo.GetPhoneNo();
            _TAMoreDetailEtiqa.OfficePhoneNo = txtOfficeNo.GetPhoneNo();
            _TAMoreDetailEtiqa.FaxNo = "";
            _TAMoreDetailEtiqa.Email = txtEmailAddress.Text;
            _TAMoreDetailEtiqa.PlanType = lblPolicyType.Text;
            _TAMoreDetailEtiqa.TripType = lblTrip.Text;
            _TAMoreDetailEtiqa.CoverageLevel = lblCover.Text;
            _TAMoreDetailEtiqa.Country = lblDestination.Text;
            _TAMoreDetailEtiqa.Area = lblDestination.Text;
            _TAMoreDetailEtiqa.Duration = lblDuration.Text;
            _TAMoreDetailEtiqa.StartDate = DateTime.Parse(lblStart.Text);
            _TAMoreDetailEtiqa.EndDate = DateTime.Parse(lblEnd.Text);
            _TAMoreDetailEtiqa.AdultAge = Convert.ToInt32(lblAdultAge.Text);
            _TAMoreDetailEtiqa.ChildAge = Convert.ToInt32(lblChildAge.Text);
            _TAMoreDetailEtiqa.NoOfTraveller = Convert.ToInt32(lblNoOfTravellers.Text);
            _TAMoreDetailEtiqa.TotalPremium = float.Parse(lblTotalPremium.Text);
            _TAMoreDetailEtiqa.PaymentType = "CreditCard";

            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));

            _TAMoreDetailEtiqa.QuoteRefNo = "TIE" + convertno.ToString();
            _TAMoreDetailEtiqa.PaymentStatus = false;

            string _totalPaymentAmount = "";
            _totalPaymentAmount = lblTotalPremium.Text;

            string _paymentOrderNo = "";
            string val = GetOrderNumber();
            string[] _orderno = val.Split(',');
            _TAMoreDetailEtiqa.OrderNo = _orderno[0].ToString();
            _paymentOrderNo = _orderno[0].ToString();
            _TAMoreDetailEtiqa.OrderSerialNo = Convert.ToInt64(_orderno[1].ToString());

            _TAMoreDetailEtiqa.Info1 = "ETIQA"; // txtEmailAddress.Text;
            //_TAMoreDetailEtiqa.Info2 = Session[General.TAId].ToString(); //AppSeaID

            if (Session[General.UserId] != null)
                _TAMoreDetailEtiqa.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
            else
                _TAMoreDetailEtiqa.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());


            _TAMoreDetailEtiqa.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _TAMoreDetailEtiqa.Status = true;

            _tamoreresult = _TAMoreDetailEtiqadb.Insert(_TAMoreDetailEtiqa);

            Int64 TATraId = 0;
            if (_tamoreresult > 0)
            {
                //Save Travellers to Insure

                int NoOfTravellers = 0; // Convert.ToInt32(lblNoOfTravellers.Text.ToString());

                string salutation = "";
                string idtype = "";
                string gender = "";
                string surname = "";
                string givenname = "";
                string idnum = "";
                DateTime birthday = CE.Global.General.GetUTCDateTime();
                string nationality = "";
                string relationship = "";

                NoOfTravellers = Convert.ToInt32(txtNoOfTravellers.Text.Trim());

                TATravellersToInsure _tatravellerstoinsure = new TATravellersToInsure();
                TATravellersToInsureDB _tatravellerstoinsuredb = new TATravellersToInsureDB();

                _InsuredType = inInsuredType.Value.Trim();

                for (int i = 1; i <= NoOfTravellers; i++)
                {
                    if (_InsuredType == "IND")
                    {
                        if (i == 1)
                        {
                            surname = txtNameOfInsured.Text.ToUpper();
                            givenname = txtNameOfInsuredGiven.Text.ToUpper();
                            idnum = ddlNRIC.GetIdNumber();//txtNRICPass.Text;
                            birthday = usrDOB.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = ddlRelationship.Text;
                            gender = usrGender.GetGender();
                        }

                    }
                    else if (_InsuredType == "INS")
                    {
                        if (i == 1)
                        {
                            surname = txtInsured.Text.ToUpper();
                            givenname = txtInsuredGiven.Text.ToUpper();
                            idnum = ddlNRICInsured.GetIdNumber();//txtNRICPass.Text;
                            birthday = usrDOBinsured.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = ddlRelationship.Text;
                            gender = usrGenderInsured.GetGender();
                        }
                        if (i == 2)
                        {
                            surname = txtSpouse.Text.ToUpper();
                            givenname = txtSpouseGiven.Text.ToUpper();
                            idnum = ddlNRICSpouse.GetIdNumber();// txtNRICPassSpouse.Text;
                            birthday = usrDOBSpouse.GetDate();
                            nationality = ddlNationality.GetNationality();
                            relationship = "Spouse";
                            gender = usrGenderSpouse.GetGender();
                        }
                    }
                    else //Family
                    {
                        if (txtNoOfAdult.Text.Trim() == "1") //Individual+Child
                        {
                            if (i == 1)
                            {
                                surname = txtNameOfInsured.Text.ToUpper();
                                givenname = txtNameOfInsuredGiven.Text.ToUpper();
                                idnum = ddlNRIC.GetIdNumber();//txtNRICPass.Text;
                                birthday = usrDOB.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = ddlRelationship.Text;
                                gender = usrGenderInsured.GetGender();
                            }
                            if (i == 2)
                            {
                                surname = txtChildName1.Text.ToUpper();
                                givenname = txtChildName1Given.Text.ToUpper();
                                idnum = ddlChildIdNumber1.GetIdNumber();
                                birthday = ddlChildDOB1.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild1.GetGender();
                            }
                            if (i == 3)
                            {
                                surname = txtChildName2.Text.ToUpper();
                                givenname = txtChildName2Given.Text.ToUpper();
                                idnum = ddlChildIdNumber2.GetIdNumber();
                                birthday = ddlChildDOB2.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild2.GetGender();
                            }
                            if (i == 4)
                            {
                                surname = txtChildName3.Text.ToUpper();
                                givenname = txtChildName3Given.Text.ToUpper();
                                idnum = ddlChildIdNumber3.GetIdNumber();
                                birthday = ddlChildDOB3.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild3.GetGender();
                            }
                            if (i == 5)
                            {
                                surname = txtChildName4.Text.ToUpper();
                                givenname = txtChildName4Given.Text.ToUpper();
                                idnum = ddlChildIdNumber4.GetIdNumber();
                                birthday = ddlChildDOB4.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild4.GetGender();
                            }
                            if (i == 6)
                            {
                                surname = txtChildName5.Text.ToUpper();
                                givenname = txtChildName5Given.Text.ToUpper();
                                idnum = ddlChildIdNumber5.GetIdNumber();
                                birthday = ddlChildDOB5.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild5.GetGender();
                            }
                            if (i == 7)
                            {
                                surname = txtChildName6.Text.ToUpper();
                                givenname = txtChildName5Given.Text.ToUpper();
                                idnum = ddlChildIdNumber6.GetIdNumber();
                                birthday = ddlChildDOB6.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild6.GetGender();
                            }
                        }
                        else
                        {
                            if (i == 1)
                            {
                                surname = txtInsured.Text.ToUpper();
                                givenname = txtInsuredGiven.Text.ToUpper();
                                idnum = ddlNRICInsured.GetIdNumber();//txtNRICPass.Text;
                                birthday = usrDOBinsured.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = ddlRelationship.Text;
                                gender = usrGenderInsured.GetGender();
                            }
                            if (i == 2)
                            {
                                surname = txtSpouse.Text.ToUpper();
                                givenname = txtSpouseGiven.Text.ToUpper();
                                idnum = ddlNRICSpouse.GetIdNumber();// txtNRICPassSpouse.Text;
                                birthday = usrDOBSpouse.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = "Spouse";
                                gender = usrGenderSpouse.GetGender();
                            }

                            if (i == 3)
                            {
                                surname = txtChildName1.Text.ToUpper();
                                givenname = txtChildName1Given.Text.ToUpper();
                                idnum = ddlChildIdNumber1.GetIdNumber();
                                birthday = ddlChildDOB1.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild1.GetGender();
                            }
                            if (i == 4)
                            {
                                surname = txtChildName2.Text.ToUpper();
                                givenname = txtChildName2Given.Text.ToUpper();
                                idnum = ddlChildIdNumber2.GetIdNumber();
                                birthday = ddlChildDOB2.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild2.GetGender();
                            }
                            if (i == 5)
                            {
                                surname = txtChildName3.Text.ToUpper();
                                givenname = txtChildName3Given.Text.ToUpper();
                                idnum = ddlChildIdNumber3.GetIdNumber();
                                birthday = ddlChildDOB3.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild3.GetGender();
                            }
                            if (i == 6)
                            {
                                surname = txtChildName4.Text.ToUpper();
                                givenname = txtChildName4Given.Text.ToUpper();
                                idnum = ddlChildIdNumber4.GetIdNumber();
                                birthday = ddlChildDOB4.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild4.GetGender();
                            }
                            if (i == 7)
                            {
                                surname = txtChildName5.Text.ToUpper();
                                givenname = txtChildName5Given.Text.ToUpper();
                                idnum = ddlChildIdNumber5.GetIdNumber();
                                birthday = ddlChildDOB5.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild5.GetGender();
                            }
                            if (i == 8)
                            {
                                surname = txtChildName6.Text.ToUpper();
                                givenname = txtChildName6Given.Text.ToUpper();
                                idnum = ddlChildIdNumber6.GetIdNumber();
                                birthday = ddlChildDOB6.GetDate();
                                relationship = "Child";
                                gender = usrGenderChild6.GetGender();
                            }
                        }
                    }


                    _tatravellerstoinsure.TATraId = 0;
                    //_tatravellerstoinsure.TAPersonnelId = _tapersonnel.TAPersonnelId;
                    _tatravellerstoinsure.TAPersonnelId = _tamoreresult;
                    _tatravellerstoinsure.ProviderCompanyId = 30;
                    _tatravellerstoinsure.Salutation = salutation;
                    _tatravellerstoinsure.Fullname = givenname + " " + surname;
                    _tatravellerstoinsure.IDType = idtype;
                    _tatravellerstoinsure.IDNumber = idnum;
                    _tatravellerstoinsure.Gender = gender;
                    _tatravellerstoinsure.Birthday = birthday;
                    _tatravellerstoinsure.Nationality = nationality;
                    _tatravellerstoinsure.Relationship = relationship;
                    _tatravellerstoinsure.Info1 = "ETIQA";

                    if (Session[General.UserId] != null)
                        _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                    else
                        _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                    _tatravellerstoinsure.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                    _tatravellerstoinsure.Status = true;

                    TATraId = _tatravellerstoinsuredb.Insert(_tatravellerstoinsure);

                }

            }

            if (TATraId > 0)
            {
                General.ClearAllSession(this.Page, "ALL");
                //Response.Redirect("~/etiqa/paymentmsg.aspx?ordernumber=" + _paymentOrderNo + "&amount=" + _totalPaymentAmount + "&authresp=OK"
                //    + "&email=" + txtEmailAddress.Text + "&authcode=1&authdt=1&cctref=1");
                //Response.Redirect("~/personal-accident/etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");
                
                Response.Redirect("https://nera.i2pay.com.sg/etiqa/etiqa_payment.html?hcrn=" + _paymentOrderNo + "&hcpa=" + _totalPaymentAmount + "&c=1");
            }

        }
    }
    
    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("TA", Request, "Travel Insurance applicant's details.");
    }

    private void CheckValidation()
    {
        int NoOfTravellers = Convert.ToInt32(lblNoOfTravellers.Text.ToString());

        usrDOBPolicyHolder.IsEnableValidation(true);
        ddlNRICPolicyHolder.IsEnableValidation(true);

        usrDOB.IsEnableValidation(false);
        usrDOBinsured.IsEnableValidation(false);
        usrDOBSpouse.IsEnableValidation(false);

        usrGenderPolicyHolder.IsEnableValidation(true);
        usrGender.IsEnableValidation(false);
        usrGenderInsured.IsEnableValidation(false);
        usrGenderSpouse.IsEnableValidation(false);

        if (divIndividual.Visible == true)
        {
            usrDOB.IsEnableValidation(true);
            ddlNRIC.IsEnableValidation(true);
            usrGender.IsEnableValidation(true);
        }
        else if (divWithspouse.Visible == true)
        {
            usrDOBinsured.IsEnableValidation(true);
            usrDOBSpouse.IsEnableValidation(true);
            ddlNRICInsured.IsEnableValidation(true);
            ddlNRICSpouse.IsEnableValidation(true);
            usrGenderInsured.IsEnableValidation(true);
            usrGenderSpouse.IsEnableValidation(true);

        }

        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);

    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Particulars of Proposer

        ddlSalutation.ChangeValidationEffectServerSide(strValidationGroup);

        if (rfvFirstname.Enabled && rfvFirstname.ValidationGroup == strValidationGroup)
        {
            rfvFirstname.Validate();
            if (rfvFirstname.IsValid == false)
            {
                txtFirstname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtFirstname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtFirstname.ControlStyle.CssClass = "";
        }


        if (rfvSurname.Enabled && rfvSurname.ValidationGroup == strValidationGroup)
        {
            rfvSurname.Validate();
            if (rfvSurname.IsValid == false)
            {
                txtSurname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSurname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSurname.ControlStyle.CssClass = "";
        }

        if (revEmailAddress.Enabled && revEmailAddress.ValidationGroup == strValidationGroup)
        {
            if (rfvEmailAddress.IsValid)
            {
                revEmailAddress.Validate();
                if (revEmailAddress.IsValid == false)
                {
                    txtEmailAddress.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmailAddress.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmailAddress.ControlStyle.CssClass = "";

        }

        //usrGEnder.ChangeValidationEffectServerSide(strValidationGroup);
        //usrIdType.ChangeValidationEffectServerSide(strValidationGroup);
        //usrIdNumber.ChangeValidationEffectServerSide(strValidationGroup);
       
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtOfficeNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtResidentialPhoneNo.ChangeValidationEffectServerSide(strValidationGroup);

        usrDOBPolicyHolder.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOB.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBinsured.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBSpouse.ChangeValidationEffectServerSide(strValidationGroup);

        ddlNRICPolicyHolder.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRIC.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRICInsured.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRICSpouse.ChangeValidationEffectServerSide(strValidationGroup);

        usrGenderPolicyHolder.ChangeValidationEffectServerSide(strValidationGroup);
        usrGender.ChangeValidationEffectServerSide(strValidationGroup);
        usrGenderInsured.ChangeValidationEffectServerSide(strValidationGroup);
        usrGenderSpouse.ChangeValidationEffectServerSide(strValidationGroup);
        //usrGenderChild1.ChangeValidationEffectServerSide(strValidationGroup);
        //usrGenderChild2.ChangeValidationEffectServerSide(strValidationGroup);
        //usrGenderChild3.ChangeValidationEffectServerSide(strValidationGroup);
        //usrGenderChild4.ChangeValidationEffectServerSide(strValidationGroup);
        //usrGenderChild5.ChangeValidationEffectServerSide(strValidationGroup);
        //usrGenderChild6.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion

        #region Travellers Info


        if (rfvNameOfInsured.Enabled && rfvNameOfInsured.ValidationGroup == strValidationGroup)
        {
            rfvNameOfInsured.Validate();
            if (rfvNameOfInsured.IsValid == false)
            {
                txtNameOfInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameOfInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameOfInsured.ControlStyle.CssClass = "";
        }

        if (rfvNameOfInsuredGiven.Enabled && rfvNameOfInsuredGiven.ValidationGroup == strValidationGroup)
        {
            rfvNameOfInsuredGiven.Validate();
            if (rfvNameOfInsuredGiven.IsValid == false)
            {
                txtNameOfInsuredGiven.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameOfInsuredGiven.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameOfInsuredGiven.ControlStyle.CssClass = "";
        }


        if (rfvInsured.Enabled && rfvInsured.ValidationGroup == strValidationGroup)
        {
            rfvInsured.Validate();
            if (rfvInsured.IsValid == false)
            {
                txtInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtInsured.ControlStyle.CssClass = "";
        }

        if (rfvSpouse.Enabled && rfvSpouse.ValidationGroup == strValidationGroup)
        {
            rfvSpouse.Validate();
            if (rfvSpouse.IsValid == false)
            {
                txtSpouse.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtSpouse.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtSpouse.ControlStyle.CssClass = "";
        }


        if (rfvNoOfChild.Enabled && rfvNoOfChild.ValidationGroup == strValidationGroup)
        {
            rfvNoOfChild.Validate();
            if (rfvNoOfChild.IsValid == false)
            {
                txtNoOfChild.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNoOfChild.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNoOfChild.ControlStyle.CssClass = "";
        }
        #endregion

    }
    
    private void ClearSession()
    {
        Session[General.TAPersonnelId] = null;
        //Session[General.TAId] = null;
        //Session[General.TAResultId] = null;
    }

    private void ShowUserDetails()
    {
        //hplEditProfile.Visible = true;
        CE.User.Profile _profile = new CE.User.Profile();
        CE.User.ProfileDB _profiledb = new ProfileDB();
        CE.User.Contact _contact = new Contact();
        CE.User.ContactDB _contactdb = new ContactDB();

        Int64 UserId = Convert.ToInt64(Session[General.UserId].ToString());
        _profile = _profiledb.GetProfile(UserId);
        if (_profile != null)
        {

            txtFirstname.Text = _profile.FirstName;
            txtSurname.Text = _profile.SurName;
            txtInsured.Text = _profile.SurName;
            txtInsuredGiven.Text = _profile.FirstName;
            txtNameOfInsured.Text = _profile.SurName;
            txtNameOfInsuredGiven.Text = _profile.FirstName;

            if (_profile.Nationality != "")
            {
                ddlNationality.Nationality = _profile.Nationality.ToString();
            }

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtOfficeNo.PhoneNo = _contact.OfficePhone;
                txtEmailAddress.Text = _contact.Email.ToString();

            }

            _profile = null;
            _profiledb = null;
            _contact = null;
            _contactdb = null;
        }


    }

    private void ChangeDateSettings()
    {
        usrDOBPolicyHolder.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
        usrDOBPolicyHolder.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrDOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
        usrDOB.EndYear = CE.Global.General.GetUTCDateTime().Year;

        usrDOBSpouse.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
        usrDOBSpouse.EndYear = CE.Global.General.GetUTCDateTime().Year;

    }

    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();          

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0 && _dt.Columns.Count >= 2)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                if (_dr["t"] != null && _dr["a"] != null)
                                {
                                    _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                    _lstText = _dr["t"].ToString();
                                    ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                    if (_rowCount == 0)
                                    {
                                        txtAddress.Text = _lstValue;
                                        //ibtPostCode.Enabled = false;
                                        txtAddress.ReadOnly = true;
                                    }

                                    _rowCount++;
                                }
                            }
                        }
                        else
                        {
                            txtAddress.Text = "Confirm postcode or enter manually.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "Confirm postcode or enter manually.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }

    private void ValidateChild1(bool OnOff)
    {
        rfvChildName1.Enabled = OnOff;
        revChildName1.Enabled = OnOff;
        ddlChildIdNumber1.IsEnableValidation(OnOff);
        usrGenderChild1.IsEnableValidation(OnOff);
    }

    private void ValidateChild2(bool OnOff)
    {
        rfvChildName2.Enabled = OnOff;
        revChildName2.Enabled = OnOff;
        ddlChildIdNumber2.IsEnableValidation(OnOff);
        usrGenderChild2.IsEnableValidation(OnOff);
    }

    private void ValidateChild3(bool OnOff)
    {
        rfvChildName3.Enabled = OnOff;
        revChildName3.Enabled = OnOff;
        ddlChildIdNumber3.IsEnableValidation(OnOff);
        usrGenderChild2.IsEnableValidation(OnOff);
    }

    private void ValidateChild4(bool OnOff)
    {
        rfvChildName4.Enabled = OnOff;
        revChildName4.Enabled = OnOff;
        ddlChildIdNumber4.IsEnableValidation(OnOff);
        usrGenderChild4.IsEnableValidation(OnOff);
    }

    private void ValidateChild5(bool OnOff)
    {
        rfvChildName5.Enabled = OnOff;
        revChildName5.Enabled = OnOff;
        ddlChildIdNumber5.IsEnableValidation(OnOff);
        usrGenderChild5.IsEnableValidation(OnOff);
    }

    private void ValidateChild6(bool OnOff)
    {
        rfvChildName6.Enabled = OnOff;
        revChildName6.Enabled = OnOff;
        ddlChildIdNumber6.IsEnableValidation(OnOff);
        usrGenderChild6.IsEnableValidation(OnOff);
    }

    private enum CardType
    {
        MasterCard, BankCard, Visa, AmericanExpress, Discover, DinersClub, JCB
    }

    protected void imgbtnBackTop_Click(object sender, ImageClickEventArgs e)
    {
        BackToResults();      
    }

    public string GetOrderNumber()
    {
        Int64 _orderserialno = 0;
        string _result, _serialno;
        _result = ""; _serialno = "";
        MyDatabase _db = new MyDatabase();
        string _firstno = CE.Global.General.GetUTCDateTime().Year + CE.Global.General.GetUTCDateTime().Month.ToString("00") + CE.Global.General.GetUTCDateTime().Day.ToString("00");

        if (Session[General.UserId] != null && Session[General.CarId] != null)
        {
            _TAId = Convert.ToInt64(Session[CE.Global.General.TAId].ToString());
            _UserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
        }
        else if (Request.Params["carid"] != null && Request.Params["customerid"] != null)
        {
            _TAId = Convert.ToInt64(lblTAId.Text);
            _UserId = Convert.ToInt64(lblCustomerId.Text);
        }


        _result = _firstno + _TAId.ToString("000000");
        string strSql = "SELECT TOP 1 OrderSerialNo FROM tblTAMoreDetail_Etiqa WHERE OrderNo IS NOT NULL ORDER BY OrderSerialNo DESC";
        DataSet _dsResult = new DataSet();
        _dsResult = null;
        _dsResult = _db.GetDataSet(strSql);
        if (_dsResult != null && _dsResult.Tables[0].Rows.Count > 0)
        {
            _orderserialno = Convert.ToInt64(_dsResult.Tables[0].Rows[0][0].ToString());
            _orderserialno = _orderserialno + 1;
            _serialno = _orderserialno.ToString("000000");
        }
        else
        {
            _orderserialno = 1;
            _serialno = _orderserialno.ToString("000000");
        }

        _result += _serialno + "," + _orderserialno.ToString();
        return _result;
    }

    protected void BackToResults()
    {
        if (Session["TAFromSummary"] != null)
        {
            if (Session["TAFromSummary"].ToString().Trim() == "1")
            {
                BackToResultsMain();
            }
            else
            {
                BackToResultsDetails();
            }
        }
        else
        {
            BackToResultsMain();
        }
    }

    private void BackToResultsMain()
    {
        if (Request.QueryString["pid"] != null)
        {
            if (Request.QueryString["pid"].ToString() != "")
            {
                Response.Redirect("~/travel-insurance/results.aspx?pid=" + Request.QueryString["pid"].ToString());
            }
            else
            {
                Response.Redirect("~/travel-insurance/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/travel-insurance/results.aspx");
        }
    }

    private void BackToResultsDetails()
    {
        if (Request.QueryString["pid"] != null)
        {
            if (Request.QueryString["pid"].ToString() != "")
            {
                Response.Redirect("~/travel-insurance/results-details.aspx?pid=" + Request.QueryString["pid"].ToString());
            }
            else
            {
                Response.Redirect("~/travel-insurance/results-details.aspx");
            }
        }
        else
        {
            Response.Redirect("~/travel-insurance/results-details.aspx");
        }
    }
}
